﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyThietBi.DAL.Models;

namespace QuanLyThietBi.DAL
{
    public class PhongBanThietBiDAO
    {
        public int SavePhongBanThietBi(PHONGBAN_THIETBI pbtb)
        {
            try
            {
                using (var en = new QuanLyThietBiEntities())
                {
                    en.PHONGBAN_THIETBI.AddObject(pbtb);
                    return en.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int DeletePBTB(PHONGBAN_THIETBI pbtb)
        {
            try
            {
                using (var en = new QuanLyThietBiEntities())
                {
                    //Lấy lên cái thiết bị dưới database
                    var tbDelete = en.PHONGBAN_THIETBI.First(t => t.id == pbtb.id);
                    en.DeleteObject(tbDelete);
                    return en.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
    }
}
